// 锁
let lock = {

}
export const tools = {
    // 打字机效果
    typeWriter: function(text, callback, field){
        if(lock[field]){
            return
        }
        lock[field] = true
        var i = 0;
        var speed = 100;
        var newText = ''
        var type = function(){
            if (i < text.length){
                newText += text.charAt(i);
                i++;
                setTimeout(()=>{
                    if(i === text.length){
                        callback(newText);
                        return ;
                    }else{
                        callback(newText + "_");
                        type()
                    }
                }, speed);
            } 
        };
        type();
    },
    // 清除所有锁
    clearLock(){
        lock = {}
    },
}